{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e684b932",
   "metadata": {},
   "outputs": [],
   "source": [
    "import OperateCardLib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bfa59b57",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "Available cards: INTEL_EDP\n",
      "card type 6\n",
      "Read DPCD Data: 14 14 C2 C1 00 00 01 C0 02 00 00 00 0F 09 80 00\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'DPCD v.': '1.4', 'Max Link Rate': '5.4Gbps/lane', 'Max Lane Count': '2-lane'}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.OperateCardLib(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        # Get the card info\n",
    "        print(card_lib.get_card_info())\n",
    "\n",
    "        # Enumerate cards\n",
    "        cards = card_lib.enum_cards()\n",
    "        print(\"Available cards:\", cards.value.decode('utf-8'))\n",
    "\n",
    "        print(\"card type\", card_lib.get_card_type())\n",
    "\n",
    "        # Select a port\n",
    "        # card_lib.select_port(1)\n",
    "        # slect_port导致N卡报错\n",
    "        # 1. AMD单显卡，选择init edp/dp控制选择内外屏\n",
    "        # 2. Intel+N卡，通过init选择内外屏\n",
    "        # 3. 单N卡，关闭屏幕实现内外屏选择\n",
    "\n",
    "        # Read/Write DPCD\n",
    "        data_to_write = bytes([0x01, 0x02, 0x03])\n",
    "    #    card_lib.write_dpcd(0x1000, data_to_write)\n",
    "        read_data = card_lib.read_dpcd(0x0000, 16)\n",
    "        print(\"Read DPCD Data:\", read_data.hex(\" \").upper())\n",
    "\n",
    "        display(card_lib.parse_dpcd(read_data))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e239d31b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read DPCD Data: 14 14 C2 C1 00 00 01 C0 02 00 00 00 0F 09 80 00\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'DPCD v.': '1.4', 'Max Link Rate': '5.4Gbps/lane', 'Max Lane Count': '2-lane'}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Parade_TC3410(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0000, 16)\n",
    "        print(\"Read DPCD Data:\", read_data.hex(\" \").upper())\n",
    "\n",
    "        display(card_lib.parse_dpcd(read_data))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "db07cf41",
   "metadata": {},
   "source": [
    "# Read VCOM"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "acb3d22d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'0x45'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Parade_TC3410(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        display(hex(card_lib.read_vcom()>>1))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bc55b4e",
   "metadata": {},
   "source": [
    "# 修改vcom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8c53a866",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Parade_TC3410(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.write_vcom(0x01)\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "134d0078",
   "metadata": {},
   "source": [
    "# 修改PMIC AVDD AVEE\n",
    "### 用于NT50805 PMIC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "a7a4e173",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Parade_TC3410(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.iic_over_aux_write(0x47,0x03,[0x1F*2])\n",
    "        card_lib.iic_over_aux_write(0x47,0x04,[0x1F])\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6118fb7",
   "metadata": {},
   "source": [
    "# 修改Gama L0值为0xFF"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d7d2dffd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Parade_TC3410(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.change_gamma(0x6c,0xFF)\n",
    "        card_lib.change_gamma(0x6d,0xFF)\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a9768fc9",
   "metadata": {},
   "source": [
    "# 获取全体Gamma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "32a7546c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gray:  ['L255+', 'L254+', 'L247+', 'l223+', 'L191+', 'L127+', 'L63+', 'L31+', 'L7+', 'L1+', 'L0+', 'L0-', 'L1-', '...']\n",
      "reg:  ['62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77']\n",
      "val:  ['ff', 'e9', 'a1', '83', '4b', '5b', '95', '66', '61', '17', '15', '15', '17', '61', '66', '95', '5b', '4b', '83', 'a1', 'e9', 'ff']\n"
     ]
    }
   ],
   "source": [
    "import OperateCardLib\n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.Parade_TC3410(dll_path)\n",
    "        card_lib.init(6)\n",
    "\n",
    "        gamma_list = []\n",
    "        for i in range(0x62, 0x77+1,1):\n",
    "            gamma_list.append(card_lib.tc3410_reg_read(0x04, i))\n",
    "\n",
    "        print(\"gray: \",[\"L255+\",\"L254+\",\"L247+\",\"l223+\",\"L191+\",\"L127+\",\"L63+\",\"L31+\",\"L7+\",\"L1+\",\"L0+\",\"L0-\",\"L1-\",\"...\"])\n",
    "        print(\"reg: \",[hex(i)[2:] for i in range(0x62, 0x77+1,1)])\n",
    "        print(\"val: \",[i.hex() for i in gamma_list])\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "\n",
    "    finally:\n",
    "        del card_lib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4f034447",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
